package common.log;


import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Layout;
import org.apache.log4j.spi.LoggingEvent;

public class LogLayout extends Layout {
  private static SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd-HH:mm:ss.S");

  private StringBuffer _buf = new StringBuffer(512);
  
  public LogLayout() {}
  public void activateOptions() {}

  public String format(LoggingEvent lEvent) {
    Object o = lEvent.getMessage();
    
    _buf.setLength(0);
    _buf.append(SIMPLE_DATE_FORMAT.format(new Date(lEvent.getTimeStamp())));
    
    if (o instanceof String[]) {
      for (String s : (String[])o) {
        _buf.append("#|").append(s);
      }
    } else {
      _buf.append("#|").append(o);
    }
    
    _buf.append(LINE_SEP);
    return _buf.toString();
  }

  public boolean ignoresThrowable() {
    return true;
  }

}
